#define _CRT_SECURE_NO_WARNINGS 1
class MedianFinder {
public:
    priority_queue<int> bmedian;
    priority_queue<int, vector<int>, greater<int>> lmedian;
    int bnum, lnum;
    MedianFinder() {
        bnum = lnum = 0;
    }

    void addNum(int num) {
        if (bnum == lnum)
        {
            if (bnum == 0 || num <= lmedian.top()) bmedian.push(num);
            else
            {
                bmedian.push(lmedian.top());
                lmedian.pop();
                lmedian.push(num);
            }
            bnum++;
        }
        else
        {
            if (num >= bmedian.top()) lmedian.push(num);
            else
            {
                lmedian.push(bmedian.top());
                bmedian.pop();
                bmedian.push(num);
            }
            lnum++;
        }
    }

    double findMedian() {
        if (bnum == lnum) return (bmedian.top() + lmedian.top()) / 2.0;
        else return bmedian.top();
    }
};

/**
 * Your MedianFinder object will be instantiated and called as such:
 * MedianFinder* obj = new MedianFinder();
 * obj->addNum(num);
 * double param_2 = obj->findMedian();
 */